package com.cswnode.Event;

import com.alibaba.fastjson.JSONObject;
import com.cswnode.Entity.Event;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.kafka.annotation.KafkaListener;
import org.springframework.kafka.core.KafkaTemplate;
import org.springframework.stereotype.Component;

/**
 * @author csw
 * @create 2020/11/1 10:47
 */

//生产者
@Component
public class EventProducer {

    @Autowired
    private KafkaTemplate kafkaTemplate;

    //处理事件
    public void fireEvent(Event event){
        //将事件发送到指定的主题上
        kafkaTemplate.send(event.getTopic(), JSONObject.toJSONString(event));//转换为json格式；
    }

}
